/**
 ******************************************************
 * 作者:朱雍
 * 备注:
 * 时间:2017年3月15日下午1:08:51
 * Copyright (c) 2017, 243813208@qq.com All Rights Reserved.
 ******************************************************
 */

package cn.sxt.yxl.question.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.sxt.yxl.common.util.PageInfoUtil;
import cn.sxt.yxl.question.dao.IAColumnsDao;
import cn.sxt.yxl.question.dao.IAItemsDao;
import cn.sxt.yxl.question.pojo.AColumns;
import cn.sxt.yxl.question.pojo.AItems;
import cn.sxt.yxl.question.service.IQuestionService;

/**
 * 类名:QuestionServiceImpl 
 * 备注:	 
 * 时间:2017年3月15日 下午1:08:51
 * 作者:朱雍
 * @since  	JDK 1.8	 
 */
@Service("questionService")
public class QuestionServiceImpl implements IQuestionService{
	@Resource
	private IAColumnsDao columnsDao;
	
	@Resource
	private IAItemsDao itemsDao;
	//查询一条记录
	@Override
	public AColumns findOneColumn(Map<String, Object> condMap) {
		
		return this.columnsDao.findOne(condMap);
	}
//保存一条记录
	@Override
	public JSONObject saveOneColumn(AColumns columns) {
		
		JSONObject resultJSON = new JSONObject();
		int res = this.columnsDao.saveOne(columns);
		if(res > 0){
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", columns.getId());
			dataJSON.put("effectCount", res);
			resultJSON.put("code", "0");
			resultJSON.put("info", "成功");
			resultJSON.put("data", dataJSON);
		}else{
			resultJSON.put("code", "1");
			resultJSON.put("info", "失败");
		}
		return resultJSON;
	}
//关键字搜索
	@Override
	public List<AColumns> findCondColumnsList(PageInfoUtil pageInfoUtil, Map<String, Object> condMap) {
		
		if(pageInfoUtil != null){
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			List<AColumns> columns = this.columnsDao.findCondList(condMap);
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal()+""));
			return columns;
		}
		return this.columnsDao.findCondList(condMap);
	}
//更新一条记录
	@Override
	public JSONObject updateOneAColumn(AColumns columns) {
		JSONObject resultJSON = new JSONObject();
		int res = this.columnsDao.saveOne(columns);
		if(res > 0){
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", columns.getId());
			dataJSON.put("effectCount", res);
			resultJSON.put("code", "0");
			resultJSON.put("info", "成功");
			resultJSON.put("data", dataJSON);
		}else{
			resultJSON.put("code", "1");
			resultJSON.put("info", "失败");
		}
		return resultJSON;
	}
//删除一条记录
	@Override
	public JSONObject deleteOneColumn(AColumns columns) {
		JSONObject resultJSON = new JSONObject();
		int res = this.columnsDao.saveOne(columns);
		if(res > 0){
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", columns.getId());
			dataJSON.put("effectCount", res);
			resultJSON.put("code", "0");
			resultJSON.put("info", "成功");
			resultJSON.put("data", dataJSON);
		}else{
			resultJSON.put("code", "1");
			resultJSON.put("info", "失败");
		}
		return resultJSON;
	}

	

	//查询一条记录
	@Override
	public AItems findOneItem(Map<String, Object> condMap) {
		
		return this.itemsDao.findOne(condMap);
	}
//保存一条记录
	@Override
	public JSONObject saveOneItem(AItems items) {
		
		JSONObject resultJSON = new JSONObject();
		int res = this.itemsDao.saveOne(items);
		if(res > 0){
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", items.getId());
			dataJSON.put("effectCount", res);
			resultJSON.put("code", "0");
			resultJSON.put("info", "成功");
			resultJSON.put("data", dataJSON);
		}else{
			resultJSON.put("code", "1");
			resultJSON.put("info", "失败");
		}
		return resultJSON;
	}
//关键字搜索
	@Override
	public List<AItems> findCondItemsList(PageInfoUtil pageInfoUtil, Map<String, Object> condMap) {
		
		if(pageInfoUtil != null){
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			List<AItems> items = this.itemsDao.findCondList(condMap);
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal()+""));
			return items;
		}
		return this.itemsDao.findCondList(condMap);
	}
//更新一条记录
	@Override
	public JSONObject updateOneAItem(AItems items) {
		JSONObject resultJSON = new JSONObject();
		int res = this.itemsDao.saveOne(items);
		if(res > 0){
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", items.getId());
			dataJSON.put("effectCount", res);
			resultJSON.put("code", "0");
			resultJSON.put("info", "成功");
			resultJSON.put("data", dataJSON);
		}else{
			resultJSON.put("code", "1");
			resultJSON.put("info", "失败");
		}
		return resultJSON;
	}
//删除一条记录
	@Override
	public JSONObject deleteOneItem(AItems items) {
		JSONObject resultJSON = new JSONObject();
		int res = this.itemsDao.saveOne(items);
		if(res > 0){
			JSONObject dataJSON = new JSONObject();
			dataJSON.put("id", items.getId());
			dataJSON.put("effectCount", res);
			resultJSON.put("code", "0");
			resultJSON.put("info", "成功");
			resultJSON.put("data", dataJSON);
		}else{
			resultJSON.put("code", "1");
			resultJSON.put("info", "失败");
		}
		return resultJSON;
	}
}

